package com.test.reggieadmin.model.setmeal;

import com.test.reggieadmin.base.BaseObserver;
import com.test.reggieadmin.base.BasePresenter;
import com.test.reggieadmin.bean.BaseBean;
import com.test.reggieadmin.bean.CategoryListBean;
import com.test.reggieadmin.bean.DishListBean;
import com.test.reggieadmin.bean.SetmealDetailsBean;

import java.util.Map;

import okhttp3.MultipartBody;

public class AddSetmealPrensenter extends BasePresenter<AddSetmealView> {

    public AddSetmealPrensenter(AddSetmealView baseView) {
        super(baseView);
    }

    /**
     * 根据条件查询分类数据
     *
     * @param type
     */
    public void categoryList(int type) {
        addDisposable(apiServer.categoryList(type), new BaseObserver<CategoryListBean>() {
            @Override
            public void onSuccess(CategoryListBean bean) {
                baseView.categoryListSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    public void categoryListDish(int type) {
        addDisposable(apiServer.categoryList(type), new BaseObserver<CategoryListBean>() {
            @Override
            public void onSuccess(CategoryListBean bean) {
                baseView.categoryListDishSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 根据条件查询对应的菜品数据
     *
     * @param categoryId
     */
    public void dishList(String categoryId) {
        addDisposable(apiServer.dishList(categoryId), new BaseObserver<DishListBean>() {
            @Override
            public void onSuccess(DishListBean bean) {
                baseView.dishListSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 文件上传
     *
     * @param part
     */
    public void upload(MultipartBody.Part part) {
        addDisposable(apiServer.upload(part), new BaseObserver<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                baseView.uploadSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 新增套餐
     *
     * @param map
     */
    public void addSetmeal(Map<String, Object> map) {
        addDisposable(apiServer.addSetmeal(map), new BaseObserver<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                baseView.addSetmealSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 根据id查询套餐信息和对应的菜品信息
     *
     * @param id
     */
    public void setmealDetails(String id) {
        addDisposable(apiServer.setmealDetails(id), new BaseObserver<SetmealDetailsBean>() {
            @Override
            public void onSuccess(SetmealDetailsBean bean) {
                baseView.setmealDetailsSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 修改套餐
     *
     * @param map
     */
    public void updateSetmeal(Map<String, Object> map) {
        addDisposable(apiServer.updateSetmeal(map), new BaseObserver<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                baseView.updateSetmealSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }
}
